import 'package:bxultimate/domain/common/result.dart';
import 'package:bxultimate/domain/intell/IntellArea.dart';
import 'package:bxultimate/domain/intell/IntellCategory.dart';
import 'package:bxultimate/domain/intell/IntellHistoryDto.dart';
import 'package:bxultimate/domain/intell/IntellPublishDto.dart';
import 'package:bxultimate/shared/util/util_http.dart';

class IntellRequest {

  // 获取情报分类
  static Future<List<IntellCategory>> getIntellCategory() async {
    var response = await UtilHttp().get(
      '/app/appQingBao/selectAllQingBaoType',
    );
    return response['data']
        .map<IntellCategory>((item) => IntellCategory.fromJson(item))
        .toList();
  }
  // 获取上报单位
  static Future<List<IntellArea>> getAreaSubByAreaCode(code) async {
    var response = await UtilHttp().get(
      '/business/sysAreaSubordination/getAreaSubByAreaCode?areaCode=' + code,
    );
    return response['data']
        .map<IntellArea>((item) => IntellArea.fromJson(item))
        .toList();
  }
  // 获取我上报的情报
  static Future<List<IntellHistoryDto>> getMyIntell() async {
    var response = await UtilHttp().get(
      '/app/appQingBao/selectByUserId',
    );
    return response['data']
        .map<IntellHistoryDto>((item) => IntellHistoryDto.fromJson(item))
        .toList();
  }

  // 上报情报
  static Future<Result> publishIntell(IntellPublishDto publishDto) async {
    var response = await UtilHttp().post(
      '/app/appQingBao',
      data: publishDto
    );
    return Result.fromJson(response['data']);
  }

}